// Vue.http.headers.common['X-CSRF-TOKEN'] = document.querySelector('#token').getAttribute('value');
var help = new Vue({
    el: '#help',
    data: {
        showLoading: false
    },
    components: {
        'loading': {
            template: '#loading-template',
        }
    }

})
// Vue.http.interceptors.push(function (request, next) {
//     console.log(help);
//     help.showLoading = true,
//     // setTimeout(help.showLoading = true, 15000)
//     setTimeout(console.log(123), 15000)
//     next(function (response) {
//         help.showLoading = false;
//         return response;
//     });
// });
function sleep(numberMillis) {
    var now = new Date();
    var exitTime = now.getTime() + numberMillis;
    while (true) {
        now = new Date(); console.log(now.getTime());
        if (now.getTime() > exitTime) {
            return;
        }
    }
}
new Vue({
    el: '#app',
    data: {
        username: '',
        userphonenum: '',
        useridcard: '',
        userstages: '',
        usernote: '',
        // webRoot : G_WEB_ROOT,
        urls: {
            insertOnlineOpt: G_WEB_ROOT + '/m/insertOnlineOpt'
        }
    },
    ready:function(){},
    methods: {
        submitForm: function (e) {
            var notGo = this.cheackIllegalData();
            if (!notGo) {
                help.showLoading = true;
                window.vuePost = this.vuePost;
                setTimeout("vuePost()", 2000);
                // setTimeout(vuePost, 2000);
            }
        },
        cheackIllegalData: function (e) {
            var Illega = true;
            var error = document.querySelector('.error');
            if (null == error) {
                Illega = false;
            }
            return Illega;
        },
        vuePost: function () {
            var params = this.username + "," + this.userphonenum + "," + this.useridcard + "," + this.userstages + "," + this.usernote;
            this.$http.post(
                this.urls.insertOnlineOpt,
                { "valStrs": params, "timestamp": new Date().getTime() },
                { emulateJSON: true }).then(function (rs) {
                    if (200 == rs.status) {
                        help.showLoading = false;
                        if (rs.body.type) { return mui.alert(msg.iSuccess); } return mui.alert(msg.wError);
                    }
                });
        }
    }
});
